package org.kineticsproject.visualizations;

import data.DataLog;
import data.Device;
import data.Exercise;

public class kmlgenerator {

	/*public static void process(String filename, Exercise exercise)
	{

		DataLog       dl;
		Device        d;
		
	    // Setup an execute data fuser 
	    DataLog fdatalog;


		System.out.println("Selected Exercise: "+exercise.getName());
		
	    fdatalog = exercise.getFusedDataLog(); //HeterogeneousTypeDataFuser.process(datalogs,datalogs.getEarliestTimestamp(),datalogs.head().head().getTimestamp(),10);

	   // Fuser fuser   	= FuserFactory.getFuser(fdatalog,datalogs.head());
	   // fuser.process(fdatalog,datalogs.head());
	    
	    // Create trace 
		Trace          trace 	= new Trace();
		GeoVisualizer  gv       = new GeoVisualizer(fdatalog,trace);  // need to change this from dl to fdatalog
		gv.process();
		
		d = exercise.getDatalogs().get(0).getDevice();

		// Color code trace 
	    TraceColorGenerator tracecg = TraceColorGeneratorFactory.getTraceColorGenerator(d,d.getSensors().get(0));
	    tracecg.process(trace);
	    
	    
	    // Create Google Earth KML 
		KMLWriter kmlwriter 	= new KMLWriter(trace, filename);
		kmlwriter.process();
	    
//		while (datalogs.hasNext())
	    {
//	    	System.out.println("DataLog Device: "+datalogs.next().getDevice().getModel());
	    }
	}
	*/
	
	public static void process(String filename, Exercise exercise)
	{
	
	//db4oHandler   db        = new db4oHandler();
	//DataLog       dl;
	Device        d;
	
    // Setup and execute data fuser 
    DataLog fdatalog = exercise.getFusedDataLog();
  //  DataLogSet 	 datalogs 		= db.getExercise(exerciseId);
    
    
    
    //db.close();
	System.out.println("Selected Exercise: "+exercise.getName());
	
  //  fdatalog = HeterogeneousTypeDataFuser.process(datalogs,datalogs.getEarliestTimestamp(),datalogs.getLatestTimestamp(),3);

   // db.store(fdatalog);
   // db.close();
   // Fuser fuser   	= FuserFactory.getFuser(fdatalog,datalogs.head());
    //fuser.process(fdatalog,datalogs.head());
    
    // Create trace 
	Trace          trace 	= new Trace();
	GeoVisualizer  gv       = new GeoVisualizer(fdatalog,trace);  // need to change this from dl to fdatalog
	gv.process();
	
	//d = datalogs.head().getDevice();
	d = exercise.getDatalogs().get(0).getDevice();

	// Colorcode trace 
    TraceColorGenerator tracecg = TraceColorGeneratorFactory.getTraceColorGenerator(null,null);
    tracecg.process(trace);
    
  //  db.store(trace);
  //  db.close();
    
    // Create Google Earth KML 
	KMLWriterTimeStamp kmlwriter 	= new KMLWriterTimeStamp();
	kmlwriter.setTrace(trace);
	kmlwriter.setFilename(filename);
	kmlwriter.init();
	kmlwriter.process();
    
//	while (datalogs.hasNext())
    {
//    	System.out.println("DataLog Device: "+datalogs.next().getDevice().getModel());
    }

	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
